package com.lingkang.dbtodoc.config;

import com.lingkang.dbtodoc.constants.HttpCode;
import com.lingkang.dbtodoc.dto.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 绫小路
 * @date 2021/1/31 23:59
 * @description
 */
@Slf4j
@RestControllerAdvice
public class HandlerException {

  //断言异常处理
  @ExceptionHandler(IllegalArgumentException.class)
  public ResponseResult illegalArgumentException(IllegalArgumentException e) {
    log.error("断言异常",e);
    return new ResponseResult(HttpCode.FAIL, e.getMessage());
  }

  @ExceptionHandler(RuntimeException.class)
  public ResponseResult runtimeException(RuntimeException e) {
    log.error("运行异常",e);
    return new ResponseResult(HttpCode.FAIL, e.getMessage());
  }

  @ExceptionHandler(Exception.class)
  public ResponseResult exception(Exception e) {
    log.error("异常",e);
    return new ResponseResult(HttpCode.FAIL, e.getMessage());
  }
}
